require 'rubygems'
require 'scrapi'


Tidy.path = "c:/windows/system32/tidy.dll"


def extraer_ultima_actualizacion(element)
  text(element).split("\r")[0]
end


def extraer_direccion(element)
  "/" + element.attributes["href"].split("http://")[1].split("/")[1..-1].to_s
end


Titulo = Scraper.define do
  process "html>head>title", :titulo => :text
  result :titulo
end


Elinks = Scraper.define do
  array :enlaces
  process "a[href^=ed2k]", :enlaces => "@href"
  result :enlaces
end


Tema_Tusseries = Scraper.define do
  process "td.row1 a[id^=tid-link]", :descripcion => :text, :enlace => :extraer_direccion
  process "td.row2 span.lastaction", :ultima_actualizacion => :extraer_ultima_actualizacion

  result :enlace, :descripcion, :ultima_actualizacion
end


Foro_Tusseries = Scraper.define do
  array :temas
  process "table.ipbtable tr", :temas => Tema_Tusseries
  result :temas
end


IndiceForo_Tusseries = Scraper.define do
  array :temas
  process "a[href^=http://www.tusseries.com/index.php?showtopic]", :temas => "@href"
  result :temas
end
